<?php

class Controller_User_Signup extends Controller
{
	function execute($request)
	{
		$form = new Form_User_Signup;

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$values = $form -> getValues();

			$user = Model::factory('user');
			
			$user -> setPassword($values['password']);
			$user -> user_id = $user -> _id = $user -> __getAutoIncrement();
			$user -> email = $values['email'];
			$user -> gender = $values['gender'];
			$user -> created = new MongoDate();
			$user -> username = $values['username'];
			
			$user -> save();
		}
		$request -> response = View::render(array('form' => $form), 'user/signup');
	}

}
